<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: 给
  Date: 2020/10/7
  Time: 8:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    //加载数据库驱动
    Class.forName("com.mysql.jdbc.Driver");

    //建立数据库连接
    String url="jdbc:mysql://localhost:3306/book";//数据库连接地址
    Connection connection= DriverManager.getConnection(url,"root","root");//第一个root为数据库的用户名 第二个root 为数据库的密码

    String sql="select * from user where username=? and password=?";//在  PreparedStatement中使用问号代替实际参数
    PreparedStatement ps=connection.prepareStatement(sql);

    ps.setString(1,request.getParameter("username"));
    ps.setString(2,request.getParameter("password"));

    //"insert into user(username,password,gender)values(?,?,?)";
    ResultSet rs=ps.executeQuery();

    while(rs.next()){
        out.print(rs.getString("username")+"-"+rs.getString(3)+"<br>");
    }



/*
    //使用Statement对象执行sql语句
    Statement stmt=connection.createStatement();

    //stme.execteUpdate()执行增改删操作的函数
    String sql="select * from user where user ";
    ResultSet rs=stmt.executeQuery(sql);//执行查询的函数 返回结果集
    while(rs.next()){
        out.print(rs.getString("username")+"-"+rs.getString(3)+"<br>");

    }
*/
%>

</body>
</html>
